package com.qf.controller;

import com.qf.entity.Emp;
import com.qf.service.EmpService;
import com.qf.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
杨威
2021/9/16
21:53
*/
@WebServlet("/add")
public class AddEmpController extends HttpServlet {
    EmpService empService=new EmpServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String name = req.getParameter("name");
        String salary = req.getParameter("salary");
        String age = req.getParameter("age");
        Emp emp=new Emp(name,Double.valueOf(salary),Integer.valueOf(age));
        int i = empService.insertEmp(emp);
        if(i>0){
            resp.sendRedirect(req.getContextPath()+"/ShowAll");
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
